<template>
  <div class="company-user">
    <index-breadcrumb :breadcrumb-list="breadcrumbList" @showStatus="showStatus"></index-breadcrumb>
    <s-label :operation-list="operationList" :is-show="labelShowStatus" @clickLabelId="clickLabelId"></s-label>
    <s-label-value :operation-list="operationList" :is-show="!labelShowStatus" :is-only="isOnly" 
    :label-id="labelId" @backShow="backShow" @choosePName="choosePName" @chooseBackName="chooseBackName"></s-label-value>
  </div>
</template>

<script>
import sLabel from "@/views/sys/sysLabel/includes/SysLabel";
import sLabelValue from "@/views/sys/sysLabel/includes/SysLabelValue";

export default {
    name: "SysLabel",
    components: {
        sLabel,
        sLabelValue,
    },
    watch: {
        labelShowStatus(val){
            if(val){
                this.breadcrumbList = [
                        {
                            title: "系统管理"
                        },
                        {
                            title: "系统参数管理",
                        }
                    ]
            }else{
                this.breadcrumbList = [
                    {
                        title: "系统管理"
                    },
                    {
                        title: "系统参数管理",
                    },
                    {
                        title: "系统参数值管理",
                    }
                ]
            }
        },
    },
    data() {
        return {
            operationList: [],
            breadcrumbList: [
                {
                    title: "系统管理"
                },
                {
                    title: "系统参数管理",
                }
            ],
            labelShowStatus: true,
            labelId: null,
            isOnly: 1,
        };
    },
    created() {
        this.getOperationList();
    },
    methods: {
        chooseBackName(){
            this.breadcrumbList = [
                {
                    title: "系统管理"
                },
                {
                    title: "系统参数管理",
                },
                {
                    title: "系统参数值管理",
                }
            ]
        },
        choosePName(val){
            this.breadcrumbList = [
                {
                    title: "系统管理"
                },
                {
                    title: "系统参数管理",
                },
                {
                    title: "系统参数值管理",
                },
                {
                    title: val,
                }
            ]
        },
        backShow(){
            this.labelShowStatus = true
        },
        showStatus(val){
            this.labelShowStatus = val
        },
        clickLabelId(id, isOnly){
            this.labelId = id
            this.labelShowStatus = false
            this.isOnly = isOnly
        },
        getOperationList() {
        this.$store.state.permissionList.forEach(item => {
            const [itemName] = item.permission.split(":");
            if (itemName === "sysLabel") {
            this.operationList = item.list.map(listItem => {
                return listItem.permission.split(":")[1];
            });
            }
            if (itemName === "permission") {
                item.list.some(listItem => {
                    const listItemType = listItem.permission.split(":")[1];
                    if (listItemType === "edit") {
                    this.operationList.push("permission:edit");
                    return true;
                }
                return false;
                });
            }
        });
        }
    }
};
</script>

<style lang="sass" scoped>

</style>
